home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Blender 2.49b / blender-2.49b-windows.exe / $_4_ / .blender / scripts / Axiscopy.py < prev    next >
Text File  |  2009-08-31  |  4KB  |  125 lines

  1. #!BPY
  2.  
  3. """ Registration info for Blender menus: <- these words are ignored
  4. Name: 'Axis Orientation Copy'
  5. Blender: 242
  6. Group: 'Object'
  7. Tip: 'Copy local axis orientation of active object to all selected meshes (changes mesh data)'
  8. """
  9.  
  10. __author__ = "A Vanpoucke (xand)"
  11. __url__ = ("blenderartists.org", "www.blender.org",
  12. "French Blender support forum, http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender")
  13. __version__ = "2 17/12/05"
  14.  
  15. __bpydoc__ = """\
  16. This script copies the axis orientation -- X, Y and Z rotations -- of the
  17. active object to all selected meshes.
  18.  
  19. It's useful to align the orientations of all meshes of a structure, a human
  20. skeleton, for example.
  21.  
  22. Usage:
  23.  
  24. Select all mesh objects that need to have their orientations changed
  25. (reminder: keep SHIFT pressed after the first, to add each new one to the
  26. selection), then select the object whose orientation will be copied from and
  27. finally run this script to update the angles.
  28.  
  29. Notes:<br>
  30.     This script changes mesh data: the vertices are transformed.<br>
  31.     Before copying the orientation to each object, the script stores its
  32. transformation matrix.    Then the angles are copied and after that the object's
  33. vertices are transformed "back" so that they still have the same positions as
  34. before.  In other words, the rotations are updated, but you won't notice that
  35. just from looking at the objects.<br>
  36.     Checking their X, Y and Z rotation values with "Transform Properties" in
  37. the 3D View's Object menu shows the angles are now the same of the active
  38. object. Or simply look at the transform manipulator handles in local transform
  39. orientation.
  40. """
  41.  
  42.  
  43. # $Id: Axiscopy.py 9470 2006-12-25 23:14:48Z campbellbarton $
  44. #
  45. #----------------------------------------------
  46. # A Vanpoucke (xand)
  47. #from the previous script realignaxis
  48. #----------------------------------------------
  49. # Communiquer les problemes et erreurs sur:
  50. #    http://www.zoo-logique.org/3D.Blender/newsportal/thread.php?group=3D.Blender
  51. # --------------------------------------------------------------------------
  52. # ***** BEGIN GPL LICENSE BLOCK *****
  53. #
  54. # Copyright (C) 2003, 2004: A Vanpoucke
  55. #
  56. # This program is free software; you can redistribute it and/or
  57. # modify it under the terms of the GNU General Public License
  58. # as published by the Free Software Foundation; either version 2
  59. # of the License, or (at your option) any later version.
  60. #
  61. # This program is distributed in the hope that it will be useful,
  62. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  63. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  64. # GNU General Public License for more details.
  65. #
  66. # You should have received a copy of the GNU General Public License
  67. # along with this program; if not, write to the Free Software Foundation,
  68. # Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  69. #
  70. # ***** END GPL LICENCE BLOCK *****
  71. # --------------------------------------------------------------------------
  72.  
  73. from Blender import *
  74. from Blender import Mathutils
  75. from Blender.Mathutils import *
  76. import BPyMessages
  77.  
  78. def realusers(data):
  79.     users = data.users
  80.     if data.fakeUser: users -= 1
  81.     return users
  82.  
  83.     
  84.  
  85. def main():
  86.     
  87.     scn_obs= Scene.GetCurrent().objects
  88.     ob_act = scn_obs.active
  89.     scn_obs = scn_obs.context
  90.     
  91.     if not ob_act:
  92.         BPyMessages.Error_NoActive()
  93.     
  94.     obs = [(ob, ob.getData(mesh=1)) for ob in scn_obs if ob != ob_act]
  95.     
  96.     for ob, me in obs:
  97.         
  98.         if ob.type != 'Mesh':
  99.             Draw.PupMenu("Error%t|Selection must be made up of mesh objects only")
  100.             return
  101.         
  102.         if realusers(me) != 1:
  103.             Draw.PupMenu("Error%t|Meshes must be single user")
  104.             return
  105.     
  106.     if len(obs) < 1:
  107.         Draw.PupMenu("Error: you must select at least 2 objects")
  108.         return
  109.     
  110.     result = Draw.PupMenu("Copy axis orientation from: " + ob_act.name + " ?%t|OK")
  111.     if result == -1:
  112.         return
  113.     
  114.     for ob_target, me_target in obs:
  115.         if ob_act.rot != ob_target.rot:
  116.             rot_target = ob_target.matrixWorld.rotationPart().toEuler().toMatrix()
  117.             rot_source = ob_act.matrixWorld.rotationPart().toEuler().toMatrix()
  118.             rot_source_inv = rot_source.copy().invert()
  119.             tx_mat = rot_target * rot_source_inv
  120.             tx_mat.resize4x4()
  121.             me_target.transform(tx_mat)
  122.             ob_target.rot=ob_act.rot
  123.  
  124. if __name__ == '__main__':
  125.     main()